package com.hntxk.cqzd.basicinfo.basepatient.action;

import com.hntxk.core.framework.model.ResponseModel;
import com.hntxk.core.util.StringUtil;
import com.hntxk.cqzd.basicinfo.basepatient.entity.BasePatient;
import com.hntxk.cqzd.basicinfo.basepatient.service.BasePatientManageService;
import com.hntxk.cqzd.basicinfo.basepatient.service.impl.BasePatientManageServiceImpl;
import com.hntxk.cqzd.common.action.CqzdBaseController;
import com.hntxk.cqzd.diacrisis.entity.TblDiacrisisInfo;
import com.hntxk.cqzd.export.service.PatientInfoService;
import com.hntxk.cqzd.export.service.impl.PatientInfoServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.logging.log4j.LogManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;


/**
 * @Description: 患者基本信息 <br>
 * @Project: CQZD <br>
 */
@Api(value="患者基本信息", tags={"[SP]患者基本信息接口"})
@Controller
@RequestMapping("cqzd/do/basepatient")
@Slf4j
public class BasePatientController extends CqzdBaseController {

    /** 查询页面的path */

    private final static String LIST_JSP_PATH = "cqzd/base/patient/basepatient_list";

    private final BasePatientManageService basePatientManageService;

    @Autowired
    public BasePatientController(@Qualifier("basePatientService") BasePatientManageService basePatientManageService) {
        super(basePatientManageService,LogManager.getLogger(BasePatientController.class));
        this.basePatientManageService = basePatientManageService;
    }

    /**
     *
     * @return 患者基本信息主页
     */
    @ApiIgnore
    @GetMapping(value = "/index")
    public String index() {
        return LIST_JSP_PATH;
    }

    /**
     * 查询基础信息
     * @param model
     * @return
     */
    @ApiOperation("查询基础信息")
    @RequestMapping(value = "/queryList",method = RequestMethod.POST, produces = PRODUCE_UTF8_JSON)
    @ResponseBody
    public ResponseModel queryBasePatient(@ModelAttribute BasePatient model) {

            //设置身份证模糊查询
            /*String patientCardId = model.getPatientCardId();
            if(StringUtil.isNotNull(patientCardId)){
                model.setPatientCardId("%"+patientCardId+"%");
            }*/
            //设置分页信息
            model.setPagination(request);
           //return  toJson(model, basePatientManageService.query2Json(BasePatientManageServiceImpl.BASE_PATIENT_MAPPER_NAMESPACE + "query", model, true));
            return basePatientManageService.query2Json(BasePatientManageServiceImpl.BASE_PATIENT_MAPPER_NAMESPACE + "query", model, true);

    }

    /**
     * 根据主键获取对象
     * @param id
     * @return
     */
    @ApiOperation("根据name查询基础信息")
    @RequestMapping(value = "/get/{id}",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String queryBasePatientByName(@PathVariable Long id) {

        try {
            //设置分页信息
            return toJson(basePatientManageService.get(id));
        } catch (Exception e) {

            return getError(e);
        }
    }

    /**
     * 添加
     * @param basePatient
     * @return
     */
    @ApiOperation("添加")
    @RequestMapping(value = "/insert",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String insertBasePatient(@ModelAttribute TblDiacrisisInfo basePatient) {
        try {
            basePatientManageService.insert(basePatient);
            return responseOk();
        } catch (Exception e) { return getError(e); }
    }


    /**
     * 修改
     * @param basePatient
     * @return
     */
    @ApiOperation("修改")
    @RequestMapping(value = "/update",method = {RequestMethod.GET,RequestMethod.POST}, produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String updateBasePatient(@ModelAttribute TblDiacrisisInfo basePatient) {
        try {
             basePatientManageService.update(basePatient);
            return responseOk();
        } catch (Exception e) { return getError(e); }
    }



    @Override
    @DeleteMapping(value = "/delete", produces= PRODUCE_UTF8_JSON)
    @ResponseBody
    public String delete()
    {
        String string=request.getParameter("ids");
        basePatientManageService.delete(string, false);
        return responseOk();
    }



    
}
